<link type="text/css" rel="stylesheet" href="{url:#css/ucenter.css}" />
{echo:JS::import('form');}
{echo:JS::import('date');}
{echo:JS::import('dialog?skin=tinysimple');}
<script type="text/javascript" charset="UTF-8" src="{url:#js/jquery.iframe-post-form.js}"></script>
<script src="{url:#js/bootstrap.js}"></script>
<div class="container clearfix">
	{widget:name=sub_navs action=ucsidebar sidebar=$sidebar act=$actionId}
	<div class="content clearfix uc-content">
		<h1 class="title"><span>注册会员：</span></h1>
		<!-- 
		<span>推广连接：<a target="blank" href="{url:/simple/reg/num/$user[number]}">
			http://www.ahcysc.com/index.php?con=simple&act=reg&num={$user[number]} 
			</a><label style="font-size:12px;">(右键复制链接地址)</label>
			</span>
			<br>
			<span>
				{set:$url=urlencode(Common::get_complete_path("/simple/reg/num/$user[number]"))}
				<img src="{url:/simple/get_qrcode_img_by_url/url/$url}"/>
			</span>
		-->	
		
		{if:isset($msg)}
		<div class="message_{$msg[0]} ie6png">{$msg[1]}</div>
		{elseif:isset($validator)}
		<div class="message_warning ie6png">{$validator['msg']}</div>
		{/if}
		
		<!--<table border="0">-->
			<!--<tr>-->
				<!--<td>-->
					<!--分享连接：<a target="blank" href="{url:/simple/reg/num/$user[number]}">-->
			<!--http://www.ahcysc.com/index.php?con=simple&act=reg&num={$user[number]} -->
			<!--</a><label style="font-size:12px;">(右键复制链接地址)</label>-->
				<!--</td>-->
			<!--</tr>-->
			<!--<tr>-->
				<!--<td>-->
					<!--{set:$url=urlencode(Common::get_complete_path("/simple/reg/num/$user[number]"))}-->
					<!--<img src="{url:/simple/get_qrcode_img_by_url/url/$url}"/>-->
				<!--</td>-->
			<!--</tr>-->
			<!--<tr>-->
				<!--<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>扫一扫 二维码</span></td>-->
			<!--</tr>-->
		<!--</table>		-->
			
		
		<div class="mt10" style="position:relative;margin-left:100px;">

			<!--<form id="info-form" class="simple" action="{url:/ucenter/reg_act}" method="post">-->
				<table class="form">
					<!-- <tr><td class="label">会员帐号：</td><td>{if:Validator::match('\d+@no.com',$info['email'])}<input type="text" pattern="email" name="email" value="{$email}" alt="邮箱格式错误"> <label></label>{else:}{$email}{/if}</td></tr> -->
					<!-- <tr><td class="label">会员级别：</td><td>{$gname|'默认分组'}</td></tr> -->
					<tr>
						<td class="label">推荐人：</td><td>
						<input type="text" pattern="required" id="tjr_name" name="tjr_name"  value="{$user[name]}" alt="推荐人不能为空">
						</td>
					</tr>
					<tr>
						<td class="label">用户名：</td><td>
						<input type="text" pattern="required" name="uname" id="uname" value="" alt="用户名不能为空" placeholder='字母数字组合'>
						</td>
					</tr>
					<tr>
						<td class="label">真实姓名：</td><td>
						<input type="text" pattern="required" name="real_name" id="real_name" value="" alt="真实姓名不能为空">
					</td>
					</tr>
					<tr>
						<td class="label">手机号：</td><td>
						<input type="text" pattern="^1[3-9]\d{9}$" name="telphone" id="telphone" value="" alt="手机号填写不正确">
					</td>
					</tr>
					<tr>
						<td class="label">身份证号：</td><td>
						<input type="text" name="identity" id="identity" value="">
					</td>
					</tr>
					<tr>
						<td class="label">登录密码：</td><td><input placeholder='6-20位字母数字组合' type="password" pattern="required" id="password" name="password" minlen="6" maxlen="20" value="" alt="密码长度为6-20位"> <label></label></td>
					</tr>
					<tr>
						<td class="label">确认登录密码：</td><td><input placeholder='6-20位字母数字组合' type="password" pattern="required" id="repassword" name="repassword" minlen="6" maxlen="20" value="" alt="密码长度为6-20位"> <label></label></td>
					</tr>
					<tr>
						<td class="label">交易密码：</td><td><input placeholder='6-20位字母数字组合' type="password" pattern="required" name="passwordtwo" id="passwordtwo" minlen="6" maxlen="20" value="" alt="密码长度为6-20位"> <label></label></td>
					</tr>
					<tr>
						<td class="label">确认交易密码：</td><td><input placeholder='6-20位字母数字组合' type="password" pattern="required" name="repasswordtwo" id="repasswordtwo" minlen="6" maxlen="20" value="" alt="密码长度为6-20位"> <label></label></td>
					</tr>
					<tr>
						<td class="label">投资级别：</td>
						<td>
							<select pattern="required" name="agent" id="agent" alt="请选择类别" style="width:210px;">
								<option value="">请选择投资级别</option>
								{query:name=grade}
								<option value="{$item['id']}">{$item['name']}({$item['money']})</option>
								{/query}
							</select>
						</td>
					</tr>
					<tr>
						<td class="label"></td>
						<td>
							<select  id="province" name ="province">
								<option value="">==省份/直辖市==</option>
								{query:name=area  where=parent_id eq 0}
								<option value="{$item['id']}">{$item['name']}</option>
								{/query}
							</select>
							<select id="city" name="city">
								<option value="">==市==</option>
							</select>
							<select id="county" name="county">
								<option value="">==县/区==</option>
							</select>
						</td>
					</tr>
					<!--<tr>-->
						<!--<td class="label">短信验证码：</td>-->
						<!--<td>-->
							<!--{if:Validator::mobi($info['mobile'])}{$mobile}{else:}-->
							<!--<input type="text" pattern="\d{6}" name="validate_code" id="validate_code" value="" alt="短信验证码为6为数字"><label></label>{/if}-->
							<!--<input type="button" value="获取短信验证码" class="btn btn-main" onclick="get_validate_code()"/>-->
						<!--</td>-->
					<!--</tr>-->

					<tr>
						<td class="label">

						</td>
						<td>
							<input type="checkbox" id="chk_read_me" name="chk_read_me" value="1">
							我已阅读并同意 &lt;&lt;<a id="user-license" style="color:red;" href="javascript:;"> {$site_title}用户注册协议 </a>&gt;&gt;
						</td>
					</tr>
					<tr>
						<td colspan="2" class="tc"><input type="button" id="button_submit" class="btn btn-main" value="提交"></td>
					</tr>
				</table>
				<!--{token:key=reg}-->
			<!--</form>-->
		</div>
	</div>
</div>
<div id="head-dialog" style="display: none">
	<div class="box" style="width:400px;">
		<h2>上传头像：</h2>
		<div class="content mt20 p10">
			<form enctype="multipart/form-data" action="{url:/ucenter/upload_head}" method="post"  id="uploadForm">
				<p><input type="file" name="imgFile" ></p>
				<p class="mt20 tc"><button class="btn" id="upload-btn">上传</button></p>
			</form>
		</div>
	</div>
</div>

<!--注册协议-->
<div class="modal fade" id="myModal_1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
						aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">注册协议：</h4>
			</div>
			<div class="modal-body" id="myModalContent">
				<div class="form-horizontal" data-validate="parsley">
					{query:name=help where=id eq 14}
					{$item['content']}
					{/query}
					<!--
                    <section class="panel panel-default">

                        <div class="panel-body">

                        </div>
                    </section>
                    -->
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
	$(function(){
		$("#button_submit").click(function(){
			var tjr_name = $("#tjr_name").val();
			var uname    = $("#uname").val();
			var real_name = $('#real_name').val();
			var telphone = $('#telphone').val();
			var identity = $('#identity').val();
			var password    = $("#password").val();
			var repassword    = $("#repassword").val();
			var passwordtwo    = $("#passwordtwo").val();
			var repasswordtwo  = $("#repasswordtwo").val();
			var agent = $("#agent").val();
			var province      = $("#province").val();
			var city          = $("#city").val();
			var county    = $("#county").val();

			if(tjr_name == '') {
				alert('推荐人不能为空!');
				return false;
			}
			if(uname == '') {
				alert('用户名不能为空!');
				return false;
			}
			else {
				var pattern_uname = /^[0-9a-zA-Z]*$/;
				if(!pattern_uname.test( uname ))
				{
					alert('用户名请输入数字和字母组合!');
					return false;
				}
			}
			if (real_name == '') {
				alert('真实姓名不能为空!');
				return false;
			}
			if (telphone == '') {
				alert('电话不能为空!');
				return false;
			}
			else {
				var pattern = /^1[3-9]\d{9}$/;
				if(!pattern.test( telphone ))
				{
					alert('请填写正确的电话号码!');
					return false;
				}
			}
			if (identity == '') {
				alert('身份证号不能为空!');
				return false;
			}
			else {
				var pattern_id = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
				if(!pattern_id.test( identity ))
				{
					alert('请填写正确的身份证号!');
					return false;
				}
			}
			if(password == '') {
				alert('登录密码不能为空!');
				return false;
			}
			if(repassword == '') {
				alert('确认登录密码不能为空!');
				return false;
			}
			if(password !== repassword) {
				alert('两次登录密码输入不一致!');
				return false;
			}
			if(passwordtwo == '') {
				alert('交易密码不能为空!');
				return false;
			}
			if(repasswordtwo == '') {
				alert('确认交易密码不能为空!');
				return false;
			}
			if(passwordtwo !== repasswordtwo) {
				alert('两次交易密码输入不一致!');
				return false;
			}
			if(agent == '') {
				alert('投资级别不能为空!');
				return false;
			}
			if(province == '') {
				alert('请选择省份/直辖市!');
				return false;
			}
			if(city == '') {
				alert('请选择市!');
				return false;
			}
			if(county == '') {
				alert('请选择县/区!');
				return false;
			}
			if ($("#chk_read_me").is(':checked') != true) {
				alert('请选择同意用户注册协议!');
				return false;
			}
			//alert(province+" "+city+" "+county);
			$.post("{url:/ucenter/reg_act}",{tjr_name:tjr_name,uname:uname,real_name:real_name,telphone:telphone,identity:identity,password:password,passwordtwo:passwordtwo,agent:agent,province:province,city:city,county:county},function(data){
//				alert(data['msg']);
				if(data['status'] == 'fail') {
					alert(data['msg']);
				} else{
					window.location.href = "{url:/ucenter/action_list}";
				}
			},'json');

		});
	});


	$("#upload-link").on("click",function (){
		art.dialog({id:'head-dialog',content:document.getElementById('head-dialog'),lock:true});
	});

	$("#uploadForm").iframePostForm({
		iframeID: 'iframe-post-form',
		json:true,
		post: function(){
			$("#upload-btn").text("上传中...")
		},
		complete: function(data){
			if(data['error']==1){
				alert(data['message']);
			}else{
				var root_url = "{url:@}"
				$("#head-pic").attr("src",root_url+data['url']+'?i='+Math.random());
				art.dialog({id:'head-dialog'}).close();
			}
			$("#upload-btn").text("上传");
		}

	});

	var form =  new Form('info-form');
	form.setValue('is_default','{$is_default}');
	$("#areas").Linkage({ url:"{url:/ajax/area_data}",selected:[{$province|0},{$city|0},{$county|0}],callback:function(data){
		var text = new Array();
		var value = new Array();
		for(i in data[0]){
			if(data[0][i]!=0){
				text.push(data[1][i]);
				value.push(data[0][i]);
			}
		}
		$("#test").val(value.join(','));
		FireEvent(document.getElementById("test"),"change");
	}});
	{if:isset($invalid)}
	autoValidate.showMsg({id:$("input[name='{$invalid['name']}']").get(0),error:true,msg:'{$invalid['msg']}'});
	
	{/if}
	
	
		function get_validate_code()
		{
			var mobile = $.trim($("#uname").val());
			if(mobile == '')
			{
				alert('手机号码不能为空');
				return;
			}
			var mobile_pattern = /^((1[3-9]\d{9})|(\d{14}))$/;
			if(!mobile_pattern.test(mobile))
			{
				alert('手机号码不合法');
				return;
			}
			
			$("#btn_get_validate").attr("disabled", true);
			$.post("{url:/simple/sms_send}",{mobile:mobile},function(result){
			      alert(result);
			      $("#btn_get_validate").attr("disabled", false);
			  });
		}
	
</script>
<script type="text/javascript">
//	$('#agent').change(function(){
//		$("#province").removeAttr('disabled');
//		$("#city").removeAttr('disabled');
//		$("#county").removeAttr('disabled');
//
//		var u_lx = $(this).val();
//		if (u_lx == 1 || u_lx == 2) {
//			$("#province").attr('disabled',true).val(0);
//			$("#city").attr('disabled',true).val(0);
//			$("#county").attr('disabled',true).val(0);
//		} else if (u_lx == 4) {
//			$("#county").attr('disabled',true).val(0);
//		}
//	});


	$(function(){
		$("#province").change(function(){
			var id = $(this).val();

			if(id == '')
			{
				$("#city").html("<option value=''>==市==</option>");
				$("#county").html("<option value=''>==县/区==</option>");
			}
			else
			{
				$.post("{url:/ucenter/transform}",{id:id},function(data){
//					alert(data);
					$("#city").html("<option value=''>==市==</option>");
					$("#county").html("<option value=''>==县/区==</option>");
					$("#city").append(data);
				},'text');
			}

		});

		$("#city").change(function(){
			var id = $(this).val();
			if(id == '')
			{
				$("#county").html("<option value=''>==县/区==</option>");
			}
			else
			{
				$.post("{url:/ucenter/transform}",{id:id},function(data){
					$("#county").html("<option value=''>==县/区==</option>");
					$("#county").append(data);
				},'text');

			}

		})

	});
</script>
<!--<script type="text/javascript">-->
	<!--{if:!empty($invalid)}-->
	<!--$("#div_msg").text("{$invalid[msg]}")-->
	<!--{/if}-->

	<!--function show_msg( msg )-->
	<!--{-->
		<!--$("#div_msg").text(msg);-->
		<!--setTimeout(function(){-->
			<!--$("#div_msg").text('');-->
		<!--},3000);-->
	<!--}-->
<!--</script>-->
<script type="text/javascript">
	$("#user-license").on("click",function(){
		$("#myModal_1").modal();
	});

</script>

